package cn.sxt.config;

import cn.sxt.service.impl.OrderServiceImpl;
import cn.xbtop.service.UserService;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.context.annotation.Bean;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/5/8 14:14
 */
//@Configuration
public class DubboConfig {
    /**
     * 声明应用名
     */
    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig config = new ApplicationConfig("ego-boot-order-service-consumer");
        return config;
    }
    /**
     * 声明注册中心配置
     */
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig config = new RegistryConfig("zookeeper://www.leige.tech:2181");
        return config;
    }
    /**
     * 引用户UserService的服务
     */
    @Bean
    public ReferenceConfig<UserService> referenceConfigUserService(OrderServiceImpl orderServiceImpl, ApplicationConfig applicationConfig, RegistryConfig registryConfig){
        ReferenceConfig<UserService> referenceConfig=new ReferenceConfig<>();
        referenceConfig.setInterface(UserService.class);
        referenceConfig.setId("userService");
        referenceConfig.setApplication(applicationConfig);
        referenceConfig.setRegistry(registryConfig);
        //给orderServiceImpl注入数据
        //orderServiceImpl.setUserService(referenceConfig.get());
        return referenceConfig;
    }
}
